package com.note.simpleshop.module.cart.dao;

import com.note.simpleshop.entity.TbCart;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface CartRepository extends JpaRepository<TbCart, String> , JpaSpecificationExecutor<TbCart> {
    List<TbCart> findByIsDelete(Integer isdelete);
    TbCart findByIsDeleteAndGoodsSpecIdAndUserId(Integer isDelete,String goodsSpecId,String userId);
    @Transactional
    @Modifying
    @Query("update TbCart  set num = ?1 where id=?2")
    void updateCart(Integer num,String id);
    TbCart findByIdAndUserIdAndIsDelete(String cartId,String userId,Integer isDelete);
    @Transactional
    @Modifying
    @Query("update TbCart  set isDelete = ?1 where id=?2")
    void deleteCart(Integer isDelete,String id);

    /***
     *
     * 获取用户购物车信息
     * @param userId
     * @param cartIds
     * @param isDelete
     * @return
     */
    List<TbCart> findByUserIdAndIdInAndIsDelete(String userId,List<String> cartIds,Integer isDelete);

}
